//评论课程id
var otherId = $("#otherId").val();
//评论类型,类型2为课程 3为直播课
var type = 3;

$(function() {
	treeMenu();
	countHeight();
	cTabFun($("#c-i-tabTitle>a")); //滚动定位

	queryComment();//评论

	var options = {
		render: "canvas",
		height: 120,
		width: 120,
		correctLevel: 0,
		text: location.href.toString()
		//,src: '/static/favicon.ico'//这里配置Logo的地址即可。
	};
	try {
		$('#c-code-image').qrcode(options);
	} catch (e) {
		options.render = "table";
		$('#c-code-image').qrcode(options);
	}
});
/**
 * 最近的一个直播播放
 */
function nowLivePlay(courseId) {
	// 评论必须先登陆
	isLogin(function () {
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "/user/live/play/getId.json",
			data: {"courseId": courseId},
			cache: true,
			success: function (result) {
				if (result.code === 0) {
					var heigth = $(window).height();
					location.href = "/user/live/play.html?nodeId=" + result.data + "&width=100%&height=" + heigth;
				} else {
					layer.msg(result.msg);
				}
			}
		});
	});
}
/**
 * 我要学习
 * @param courseId 课程ID
 */
function buyNow(courseId) {
	var loseTime = new Date();
	//到期类型
	var nowDAte = new Date();
	if (loseTime > nowDAte) {
		//添加到购物车 并跳转
		window.location.href = "/cart/index.html?goodsId=" + courseId + "&type=1&command=addShopItem";
	} else {
		layer.msg("对不起，直播已过期!");
	}
}

/**
 * 加入购物车
 * @param courseId
 */
function addShoppingCart(courseId) {
	//添加到购物车
	$.ajax({//验证课程金额
		url: "/cart/ajax/add.json",
		data: {
			"goodsId": courseId,
			"type": "1"
		},
		type: "post",
		dataType: "json",
		success: function (result) {
			if (result.code === 401) {
				window.location.href = "/auth/login.html";
			} else if (result.code !== 0) {
				layer.msg(result.msg);
			} else {
				cShopcar();//购物车飞入效果
				//window.location.href="/cart/index.html?goodsId="+courseId+"&type=1&command=addShopItem";
			}
		}
	});
}
//购物车飞入效果
var cShopcar=function(){
	// 元素以及其他一些变量
	var eleFlyElement = document.querySelector("#flyItem"), eleShopCart = document.querySelector("#shopCart");

	// 抛物线运动
	var myParabola = funParabola(eleFlyElement, eleShopCart, {
		speed: 400, //抛物线速度
		curvature: 0.0008, //控制抛物线弧度
		complete: function() {
			eleFlyElement.style.visibility = "hidden";
			eleShopCart.querySelector("tt").innerHTML = ++numberItem;
		}
	});
	// 绑定点击事件
	if (eleFlyElement && eleShopCart) {

		[].slice.call(document.getElementsByClassName("btnCart")).forEach(function(event) {
			//button.addEventListener("click", function(event) {
			//button.click(function(event) {
			//var src = $(this).parent().parent().parent().parent().siblings(".c-v-pic-wrap").find('.p-h-video-box').find("img").attr("src");
			var src = $("#aCoursesList").find("article.c-v-pic-wrap").find('.p-h-video-box').find("img").attr("src");
			$("#flyItem").find("img").attr("src", src);
			// 滚动大小
			var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft || 0,
				scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
			eleFlyElement.style.left = event.clientX + scrollLeft + "px";
			eleFlyElement.style.top = event.clientY + scrollTop + "px";
			eleFlyElement.style.visibility = "visible";

			// 需要重定位
			myParabola.position().move();
			//});
		});
	}
};
/*课程简介、列表、评论点击切换显示对应内容*/
function selectCourseInfo(infoId) {
	$("#liveContext,#liveList,#liveComment").hide();
	$("#" + infoId).show();
	if (isMobileBrowser() == false) {
		var height = $(".cou-in-boc").height();
		/*如果小于要切换出的模块高度 将他的高度设置为auto */
		if (height < $("#" + infoId).height()) {
			$(".cou-in-boc").height("auto");
			/*如果不小于要切换出的模块高度 则将高度设置为原高度 */
		} else if ($("#" + infoId).height() < height) {
			$(".cou-in-boc").height(height)
		}
	}
}

function countHeight() {
	if (isMobileBrowser() === false) {
		/*计算课程详情部分高度 赋值给简介部分高度*/
		var height = $(".liveInfoRight").height() - 20;
		if ($(".cou-in-boc").height() < height) {
			$(".cou-in-boc").height(height);
		}
	}
}
//直播倒计时
/*
function conDowFun() {
	var second = ${not empty liveTime?liveTime:0}; // 剩余秒数

	ss = second%1000;
	second = (second -ss)/1000;
	//写一个方法，将秒数专为天数
	if (second > 0) {

		var toDays = function () {
			var s = second % 60; // 秒
			if (s < 10) {
				s = "0" + s;
			}
			var mi = (second - s) / 60 % 60; // 分钟
			var h = ((second - s) / 60 - mi ) / 60 % 24; // 小时
			if (h < 10) {
				h = "0" + h;
			}
			var d = (((second - s) / 60 - mi ) / 60 - h ) / 24; // 天
			return "直播倒计时：<tt>" + d + "</tt>天<tt>" + h + "</tt>时<tt>" + mi + "</tt>分<tt>" + s + "</tt>秒";
		};
		//然后写一个定时器
		window.setInterval(function () {
			if (second > 0) {
				second--;
			}
			document.getElementById("showTimes").innerHTML = toDays();
		}, 1000);
	}
}*/
